package com.lywz.biz.dao.city.impl;

import java.util.Collection;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.lywz.biz.common.dao.AbstractBaseDao;
import com.lywz.biz.common.entity.city.CityEntertainment;
import com.lywz.biz.common.entity.city.CityInfo;
import com.lywz.biz.common.entity.city.CityTourismOrganization;
import com.lywz.biz.common.entity.city.CityTraffic;
import com.lywz.biz.dao.city.CityDao;
import com.lywz.core.util.CommonDefaultCheck;

@Repository("cityDao")
public class CityDaoImpl extends AbstractBaseDao implements CityDao {

    @SuppressWarnings("unchecked")
    @Override
    public Collection<CityInfo> getOverview() throws Exception {
        Query query = session().getNamedQuery("city.queryCitys");
        return (Collection<CityInfo>) CommonDefaultCheck.checkDefault(query.list());
    }

    @SuppressWarnings("unchecked")
    @Override
    public Collection<CityTourismOrganization> getInsideOrgByCityId(Short cityId) throws Exception {
        Query query = session().getNamedQuery("city.queryInsideOrg");
        query.setShort("cityId", cityId);
        return (Collection<CityTourismOrganization>) CommonDefaultCheck.checkDefault(query.list());
    }

    @SuppressWarnings("unchecked")
    @Override
    public Collection<CityTourismOrganization> getOutsideOrgByCityId(Short cityId) throws Exception {
        Query query = session().getNamedQuery("city.queryOutsideOrg");
        query.setShort("cityId", cityId);
        return (Collection<CityTourismOrganization>) CommonDefaultCheck.checkDefault(query.list());
    }

    @SuppressWarnings("unchecked")
    @Override
    public Collection<CityTraffic> getCityTrafficList() throws Exception {
        Query query = session().getNamedQuery("cityTraffic.list");
        return (Collection<CityTraffic>) CommonDefaultCheck.checkDefault(query.list());
    }

    @SuppressWarnings("unchecked")
    @Override
    public CityTraffic getOneCityTrafficByCityId(Short cityId) throws Exception {
        Query query = session().getNamedQuery("cityTraffic.one");
        query.setShort("cityId", cityId);
        List<CityTraffic> cityTrafficList = query.list();
        return cityTrafficList.size() > 0 ? cityTrafficList.get(0) : new CityTraffic();
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public CityEntertainment getCityEntertainmentByCityId(Short cityId) throws Exception
    {
        Query query = session().getNamedQuery("city.entertainmentByCityId");
        query.setShort("cityId", cityId);
        List<CityEntertainment> cityEntertainmentList = query.list();
        return cityEntertainmentList.size() > 0 ? cityEntertainmentList.get(0) : new CityEntertainment();     
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public Collection<CityEntertainment> getCityEntertainmentList() throws Exception
    {
        Query query = session().getNamedQuery("city.entertainmentList");
        return (Collection<CityEntertainment>) CommonDefaultCheck.checkDefault(query.list());
    }

}
